/* add user code begin Header */
/**
  **************************************************************************
  * @file     at32f403a_407_int.c
  * @brief    main interrupt service routines.
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */
/* add user code end Header */

/* includes ------------------------------------------------------------------*/
#include "at32f403a_407_int.h"

/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
#include "at32f403a_407_board.h"
/* add user code end private includes */

/* private typedef -----------------------------------------------------------*/
/* add user code begin private typedef */

/* add user code end private typedef */

/* private define ------------------------------------------------------------*/
/* add user code begin private define */

/* add user code end private define */

/* private macro -------------------------------------------------------------*/
/* add user code begin private macro */

/* add user code end private macro */

/* private variables ---------------------------------------------------------*/
/* add user code begin private variables */

/* add user code end private variables */

/* private function prototypes --------------------------------------------*/
/* add user code begin function prototypes */

/* add user code end function prototypes */

/* private user code ---------------------------------------------------------*/
/* add user code begin 0 */
extern void xPortSysTickHandler(void);
/* add user code end 0 */

/* external variables ---------------------------------------------------------*/
/* add user code begin external variables */

/* add user code end external variables */

/**
  * @brief  this function handles nmi exception.
  * @param  none
  * @retval none
  */
void NMI_Handler(void)
{
  /* add user code begin NonMaskableInt_IRQ 0 */

  /* add user code end NonMaskableInt_IRQ 0 */

  /* add user code begin NonMaskableInt_IRQ 1 */

  /* add user code end NonMaskableInt_IRQ 1 */
}

/**
  * @brief  this function handles hard fault exception.
  * @param  none
  * @retval none
  */
void HardFault_Handler(void)
{
  /* add user code begin HardFault_IRQ 0 */

  /* add user code end HardFault_IRQ 0 */
  /* go to infinite loop when hard fault exception occurs */
  while (1)
  {
    /* add user code begin W1_HardFault_IRQ 0 */

    /* add user code end W1_HardFault_IRQ 0 */
  }
}

/**
  * @brief  this function handles memory manage exception.
  * @param  none
  * @retval none
  */
void MemManage_Handler(void)
{
  /* add user code begin MemoryManagement_IRQ 0 */

  /* add user code end MemoryManagement_IRQ 0 */
  /* go to infinite loop when memory manage exception occurs */
  while (1)
  {
    /* add user code begin W1_MemoryManagement_IRQ 0 */

    /* add user code end W1_MemoryManagement_IRQ 0 */
  }
}

/**
  * @brief  this function handles bus fault exception.
  * @param  none
  * @retval none
  */
void BusFault_Handler(void)
{
  /* add user code begin BusFault_IRQ 0 */

  /* add user code end BusFault_IRQ 0 */
  /* go to infinite loop when bus fault exception occurs */
  while (1)
  {
    /* add user code begin W1_BusFault_IRQ 0 */

    /* add user code end W1_BusFault_IRQ 0 */
  }
}

/**
  * @brief  this function handles usage fault exception.
  * @param  none
  * @retval none
  */
void UsageFault_Handler(void)
{
  /* add user code begin UsageFault_IRQ 0 */

  /* add user code end UsageFault_IRQ 0 */
  /* go to infinite loop when usage fault exception occurs */
  while (1)
  {
    /* add user code begin W1_UsageFault_IRQ 0 */

    /* add user code end W1_UsageFault_IRQ 0 */
  }
}

/**
  * @brief  this function handles svcall exception.
  * @param  none
  * @retval none
  */
//void SVC_Handler(void)
//{
//  /* add user code begin SVCall_IRQ 0 */

//////////////////  /* add user code end SVCall_IRQ 0 */
//  /* add user code begin SVCall_IRQ 1 */

//////////////////  /* add user code end SVCall_IRQ 1 */
//}

/**
  * @brief  this function handles debug monitor exception.
  * @param  none
  * @retval none
  */
void DebugMon_Handler(void)
{
  /* add user code begin DebugMonitor_IRQ 0 */

  /* add user code end DebugMonitor_IRQ 0 */
  /* add user code begin DebugMonitor_IRQ 1 */

  /* add user code end DebugMonitor_IRQ 1 */
}

/**
  * @brief  this function handles pendsv_handler exception.
  * @param  none
  * @retval none
  */
//void PendSV_Handler(void)
//{
//  /* add user code begin PendSV_IRQ 0 */

//////////////////  /* add user code end PendSV_IRQ 0 */
//  /* add user code begin PendSV_IRQ 1 */

//////////////////  /* add user code end PendSV_IRQ 1 */
//}

/**
  * @brief  this function handles systick handler.
  * @param  none
  * @retval none
  */
void SysTick_Handler(void)
{
  /* add user code begin SysTick_IRQ 0 */

    #if (INCLUDE_xTaskGetSchedulerState  == 1 )
      if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
      {
    #endif  /* INCLUDE_xTaskGetSchedulerState */  
        xPortSysTickHandler();
    #if (INCLUDE_xTaskGetSchedulerState  == 1 )
      }
    #endif  /* INCLUDE_xTaskGetSchedulerState */
  /* add user code begin SysTick_IRQ 1 */


}

/**
  * @brief  this function handles RTC handler.
  * @param  none
  * @retval none
  */
void RTC_IRQHandler(void)
{
  /* add user code begin RTC_IRQ 0 */

  /* add user code end RTC_IRQ 0 */
  /* add user code begin RTC_IRQ 1 */

  /* add user code end RTC_IRQ 1 */
}

/**
  * @brief  this function handles TMR1 Overflow and TMR10 handler.
  * @param  none
  * @retval none
  */
void TMR1_OVF_TMR10_IRQHandler(void)
{
  /* add user code begin TMR1_OVF_TMR10_IRQ 0 */
    TMR3_GLOBAL_IRQHandler();
    TMR1_GLOBAL_IRQHandler();
  /* add user code end TMR1_OVF_TMR10_IRQ 0 */
  /* add user code begin TMR1_OVF_TMR10_IRQ 1 */

  /* add user code end TMR1_OVF_TMR10_IRQ 1 */
}

/**
  * @brief  this function handles USART1 handler.
  * @param  none
  * @retval none
  */
void USART1_IRQHandler(void)
{
  /* add user code begin USART1_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   
    
    if(usart_interrupt_flag_get(USART1,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(USART1);
       
        usart_data_receive(USART1);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end USART1_IRQ 0 */
  /* add user code begin USART1_IRQ 1 */

  /* add user code end USART1_IRQ 1 */
}

/**
  * @brief  this function handles USART2 handler.
  * @param  none
  * @retval none
  */
void USART2_IRQHandler(void)
{
  /* add user code begin USART2_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   //����
    
    if(usart_interrupt_flag_get(USART2,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(USART2);
        
        usart_data_receive(USART2);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end USART2_IRQ 0 */
  /* add user code begin USART2_IRQ 1 */

  /* add user code end USART2_IRQ 1 */
}

/**
  * @brief  this function handles USART3 handler.
  * @param  none
  * @retval none
  */
void USART3_IRQHandler(void)
{
  /* add user code begin USART3_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   //����
    
    if(usart_interrupt_flag_get(USART3,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(USART3);
        
        usart_data_receive(USART3);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end USART3_IRQ 0 */
  /* add user code begin USART3_IRQ 1 */

  /* add user code end USART3_IRQ 1 */
}

/**
  * @brief  this function handles EXINT Line [15:10] handler.
  * @param  none
  * @retval none
  */
void EXINT15_10_IRQHandler(void)
{
  /* add user code begin EXINT15_10_IRQ 0 */
  if(exint_interrupt_flag_get(EXINT_LINE_12) != RESET)
  {
    //PA12中断告警
    exint_flag_clear(EXINT_LINE_12);
  }
  /* add user code end EXINT15_10_IRQ 0 */
  /* add user code begin EXINT15_10_IRQ 1 */

  /* add user code end EXINT15_10_IRQ 1 */
}

/**
  * @brief  this function handles UART4 handler.
  * @param  none
  * @retval none
  */
void UART4_IRQHandler(void)
{
  /* add user code begin UART4_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   //����
    /*�����ж�*/
    if(usart_interrupt_flag_get(UART4,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(UART4);
        
        usart_data_receive(UART4);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end UART4_IRQ 0 */
  /* add user code begin UART4_IRQ 1 */

  /* add user code end UART4_IRQ 1 */
}

/**
  * @brief  this function handles UART5 handler.
  * @param  none
  * @retval none
  */
void UART5_IRQHandler(void)
{
  /* add user code begin UART5_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   //����
   
    if(usart_interrupt_flag_get(UART5,USART_IDLEF_FLAG)!=RESET)
    {      
       
        USART_DMA_Receive_Data(UART5);
        
        usart_data_receive(UART5);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end UART5_IRQ 0 */
  /* add user code begin UART5_IRQ 1 */

  /* add user code end UART5_IRQ 1 */
}

/**
  * @brief  this function handles USART6 handler.
  * @param  none
  * @retval none
  */
void USART6_IRQHandler(void)
{
  /* add user code begin USART6_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   //����
    
    if(usart_interrupt_flag_get(USART6,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(USART6);
        
        usart_data_receive(USART6);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end USART6_IRQ 0 */
  /* add user code begin USART6_IRQ 1 */

  /* add user code end USART6_IRQ 1 */
}

/**
  * @brief  this function handles UART7 handler.
  * @param  none
  * @retval none
  */
void UART7_IRQHandler(void)
{
  /* add user code begin UART7_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR();   //����
   
    if(usart_interrupt_flag_get(UART7,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(UART7);
        
        usart_data_receive(UART7);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus );   //�˳�
  /* add user code end UART7_IRQ 0 */
  /* add user code begin UART7_IRQ 1 */

  /* add user code end UART7_IRQ 1 */
}

/**
  * @brief  this function handles UART8 handler.
  * @param  none
  * @retval none
  */
void UART8_IRQHandler(void)
{
  /* add user code begin UART8_IRQ 0 */
//    UBaseType_t uxSavedInterrupStatus;
//    uxSavedInterrupStatus=taskENTER_CRITICAL_FROM_ISR(); 
    
    if(usart_interrupt_flag_get(UART8,USART_IDLEF_FLAG)!=RESET)
    {      
        
        USART_DMA_Receive_Data(UART8);
        
        usart_data_receive(UART8);
    }
//   taskEXIT_CRITICAL_FROM_ISR( uxSavedInterrupStatus ); 
  /* add user code end UART8_IRQ 0 */
  /* add user code begin UART8_IRQ 1 */

  /* add user code end UART8_IRQ 1 */
}

/* add user code begin 1 */

/* add user code end 1 */
